﻿<%@ Page Language="C#" ValidateRequest="false" AutoEventWireup="true" CodeBehind="productEdit.aspx.cs"
    Inherits="PeisongWeb.admin.productEdit" %>

<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<%@ Register TagName="menu" Src="controls/menu.ascx" TagPrefix="uc2" %>
<%@ Register TagName="top" Src="controls/top.ascx" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>商品编辑 - 想购网长期采购物流配送系统</title>
    <!--#include file="style.inc"-->

    <script type="text/javascript" language="javascript" src="../app_common/scripts/jquery-1.3.2.js"></script>

    <script type="text/javascript" language="javascript" src="../app_common/scripts/ajaxfileupload.js"></script>

    <script type="text/javascript" src="../app_common/scripts/winClose.js"></script>


    <script type="text/javascript">
        function checkForm() {
            var buyers = "";
            $("input[id^='chk_buyerRange']").each(function(i, n) {
                if ($(n).attr("checked")) {
                    buyers += $(n).val() + ",";
                }
            });
            $("#hd_buyers").val(buyers);            
        }
        $(function() {
            $("#checkedAll").click(function() {
                if ($(this).attr("checked") == true) { // 全选
                    $("input[id^='chk_buyerRange']").each(function() {
                        $(this).attr("checked", true);
                    });
                } else { // 取消全选
                    $("input[id^='chk_buyerRange']").each(function() {
                        $(this).attr("checked", false);
                    });
                }
            });
        });


        function getProductNo() {
            var category = document.getElementById("drp_Type").value;
            //alert(category)
            if (category != "") {
                if (window.XMLHttpRequest) {
                    xh = new XMLHttpRequest();
                }
                else if (window.ActiveXObject) {
                    xh = new ActiveXObject("Microsoft.XMLHTTP"); //IE
                }
                xh.open("POST", "product.ashx?Param=getproductno&category=" + category, false);
                xh.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
                xh.send(null);
                //alert(xh.responseText)
                document.getElementById("txt_ProductNo").value = xh.responseText;
            }

        }

        function refreshUploader() {

            var who = document.getElementsByName("sp_file")[0];
            var who2 = who.cloneNode(true);
            who2.onchange = who.onchange; // events are not cloned 
            who.parentNode.replaceChild(who2, who);
        }

        function ajaxFileUpload() {

            $.ajaxFileUpload
		(
			{
			    url: 'files.ashx?Param=uploadfiles',
			    secureuri: false,
			    fileElementId: 'File1',
			    dataType: 'json',
			    success: function(data, status) {
			        if (typeof (data.error) != 'undefined') {
			            if (data.error != '') {
			                alert(data.error);
			            } else {
			                bindPhotoList(data.fileid, data.filename);
			            }

			        }
			    }
			    ,
			    error: function(data, status, e) {
			        alert(e);
			    }
			}
		);

            return false;

        }

        function bindPhotoList(fileid, filename) {
            var txt = document.getElementById("hid_photolist").value;
            txt += (txt == "" ? "" : ",") + fileid + "," + filename;
            //alert(txt);
            if (txt == "0" || txt == "") {
                document.getElementById("photoList").innerHTML = "";
                document.getElementById("hid_photolist").value = "";
                document.getElementById('hd_str').value = "";

            }
            else {

                var photos = txt.split(",");

                var strs = "";
                for (var i = 0; i < photos.length; i = i + 2) {

                    strs += getphotolistStr(photos[i], photos[i + 1]);
                }

                document.getElementById("hid_photolist").value = txt;
                document.getElementById('hd_str').value = txt;
                document.getElementById("photoList").innerHTML = strs;
            }

        }
        function bindPhotoList2(txt) {
            if (txt == "0" || txt == "") {
                document.getElementById("photoList").innerHTML = "";
                document.getElementById("hid_photolist").value = "";
                document.getElementById('hd_str').value = "";

            }
            else {

                var photos = txt.split(",");

                var strs = "";
                for (var i = 0; i < photos.length; i = i + 2) {

                    strs += getphotolistStr(photos[i], photos[i + 1]);
                }

                document.getElementById("hid_photolist").value = txt;
                document.getElementById('hd_str').value = txt;
                document.getElementById("photoList").innerHTML = strs;
            }

        }

        function getphotolistStr(id, name) {
            var strs = "<li>";
            strs += "<a href='../upload_files/thumbnail1/" + name + "' target='_blank'><img src='../upload_files/thumbnail2/" + name + "' id='img_" + id + "' alt='' /></a> ";
            strs += "<br/> <a href='javascript:removePhoto(" + id + ")'>删除</a> ";
            strs += "</li>";
            return strs;

        }

        function removePhoto(id) {
            Ext.Msg.confirm('确认', '您确定要执行此操作吗？', function(btn) {
                if (btn == "yes") {
                    $.ajax({
                        url: 'files.ashx',
                        type: 'GET',
                        dataType: "json",
                        data: { Param: "delfile", fileid: id },
                        cache: false,
                        success: function(json) {
                            removeBindPhoto(id);
                        }
                    });

                }
            });

        }

        function removeBindPhoto(id) {
            var txt = document.getElementById("hid_photolist").value;
            var newTxt = "";
            if (txt == "0" || txt == "") {
                document.getElementById("photoList").innerHTML = "";
                document.getElementById("hid_photolist").value = "";
                document.getElementById('hd_str').value = "";

            }
            else {

                var photos = txt.split(",");

                var strs = "";
                for (var i = 0; i < photos.length; i = i + 2) {
                    if (photos[i] != id) {
                        strs += getphotolistStr(photos[i], photos[i + 1]);
                        if (newTxt == "")
                            newTxt += photos[i] + "," + photos[i + 1];
                        else
                            newTxt += "," + photos[i] + "," + photos[i + 1];
                    }
                }

                document.getElementById("hid_photolist").value = newTxt;
                document.getElementById('hd_str').value = newTxt;
                document.getElementById("photoList").innerHTML = strs;
                //alert(document.getElementById("hid_photolist").value)
            }

        }



        function ClientValPhotos(source, arguments) {

            if (document.getElementById("hid_photolist").value == "0" || document.getElementById("hid_photolist").value == "") {

                arguments.IsValid = false;
            }
            else
                arguments.IsValid = true;
        }
        

        
    </script>

</head>
<body>
    <form id="form1" runat="server" onsubmit="return checkForm();">
    <ext:ScriptManager ID="ScriptManager1" runat="server" />
    <uc1:top ID="Top1" runat="server" />
    <uc2:menu ID="Menu1" runat="server" />
    <div id="admin_main" style="margin: 10px 0 0 10px;">
        <ext:Panel ID="panel_Title" runat="server" Title="商品编辑" BodyStyle="padding:5px 5px 0"
            Width="650" Frame="true" ButtonAlign="Center">
            <Body>
                <ext:Panel ID="Panel3" runat="server">
                    <Body>
                        <ext:ColumnLayout ID="ColumnLayout1" runat="server">
                            <ext:LayoutColumn ColumnWidth=".5">
                                <ext:Panel ID="Panel4" runat="server" Border="false" Header="false">
                                    <Body>
                                        <div id="admin_edit_content">
                                            <ul>
                                                <li>
                                                    <label>
                                                        名 称 *
                                                    </label>
                                                    <asp:TextBox runat="server" ID="txt_Name"></asp:TextBox>
                                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="请输入名称"
                                                        ControlToValidate="txt_Name" Display="Dynamic"></asp:RequiredFieldValidator>
                                                </li>
                                                <li>
                                                    <label>
                                                        类 别 *
                                                    </label>
                                                    <select runat="server" id="drp_Type" onchange="getProductNo()">
                                                    </select>
                                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="请选择类别"
                                                        ControlToValidate="drp_Type" Display="Dynamic"></asp:RequiredFieldValidator>
                                                </li>
                                                <li>
                                                    <label>
                                                        编 号 *
                                                    </label>
                                                    <asp:TextBox runat="server" ID="txt_ProductNo" MaxLength="10"></asp:TextBox>
                                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="请输入编号"
                                                        ControlToValidate="txt_ProductNo" Display="Dynamic"></asp:RequiredFieldValidator>
                                                </li>
                                                <li>
                                                    <label>
                                                        计量单位 *
                                                    </label>
                                                    <asp:TextBox runat="server" ID="txt_Unit"></asp:TextBox>
                                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="请输入计量单位"
                                                        ControlToValidate="txt_Unit" Display="Dynamic"></asp:RequiredFieldValidator>
                                                </li>
                                                <li>
                                                    <label>
                                                        简要规格
                                                    </label>
                                                    <asp:TextBox runat="server" ID="txt_Standard" Width="200"></asp:TextBox>
                                                </li>
                                                <li>
                                                    <label>
                                                        规格描述
                                                    </label>
                                                    <ext:HtmlEditor Width="500" Height="200" ID="html_StandardInfor" runat="server" />
                                                </li>
                                                <li>
                                                    <label>
                                                        描 述
                                                    </label>
                                                    <ext:HtmlEditor Width="500" Height="200" ID="html_Details" runat="server" />
                                                </li>
                                                <li>
                                                    <label>
                                                        自动加价 *
                                                    </label>
                                                    <asp:TextBox runat="server" ID="txt_AutoAdd" Text="0" Width="50"></asp:TextBox>
                                                    (例：0.20表示20%)
                                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ErrorMessage="请输入自动加价"
                                                        ControlToValidate="txt_AutoAdd" Display="Dynamic"></asp:RequiredFieldValidator>
                                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="txt_AutoAdd"
                                                        Display="Dynamic" ErrorMessage="请输入有效的自动加价比例" ValidationExpression="\d{1,10}\.*\d{0,2}"></asp:RegularExpressionValidator>
                                                </li>
                                                <%-- <li runat="server" id="liAutoPercent" visible="false">
                                                    <label>
                                                        企业加价比例*</label>
                                                    <asp:TextBox runat="server" ID="txt_AutoPercent" Width="50" Text="0.02"></asp:TextBox>
                                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ErrorMessage="请输入企业加价比例"
                                                        ControlToValidate="txt_AutoPercent" Display="Dynamic"></asp:RequiredFieldValidator>
                                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txt_AutoPercent"
                                                        Display="Dynamic" ErrorMessage="请输入有效的企业加价比例" ValidationExpression="\d{1,10}\.*\d{0,2}"></asp:RegularExpressionValidator>
                                                    <br />
                                                    <font color="red">(例：0.02表示2%,为所有企业购买该商品的加价比例，若需修改请到企业列表中编辑企业价格体系)</font> </li>--%>
                                                <li>
                                                    <label>
                                                        是否销售
                                                    </label>
                                                    <asp:CheckBox runat="server" ID="cbx_IsSale" />是 </li>
                                                <li>
                                                    <label>
                                                        自动生成价格
                                                    </label>
                                                    <asp:CheckBox runat="server" ID="cbx_IsAutoPrice" />是 </li>
                                                <li>
                                                    <label>
                                                        时价商品
                                                    </label>
                                                    <asp:CheckBox runat="server" ID="cbx_IsCurrentPrice" />是 </li>
                                                <li>
                                                    <label>
                                                        图 片
                                                    </label>
                                                    <span id="sp_file">
                                                        <input id="File1" type="file" name="fileToUpload" style="height: 22px;" />
                                                        <input id="input_uploadPhoto" type="button" value=" 上 传 " onclick="return ajaxFileUpload();"
                                                            style="height: 22px;" />
                                                    </span>
                                                    <asp:CustomValidator ID="CustomValidator2" runat="server" ErrorMessage="请上传图片" ClientValidationFunction="ClientValPhotos"></asp:CustomValidator>
                                                </li>
                                                <li>
                                                    <label>
                                                        &nbsp;
                                                    </label>
                                                    <ul id="photoList">
                                                    </ul>
                                                    <input id="hid_photolist" runat="server" type="hidden" />
                                                </li>
                                                <li>
                                                    <label>
                                                        采购企业
                                                    </label>
                                                    <input type="checkbox" id="checkedAll" />全选 </li>
                                                <li>
                                                    <div style="height: 300px; overflow: scroll; border: 1px solid #999999; width: auto">
                                                        <table>
                                                            <asp:Repeater runat="server" ID="rpt_buyerRange">
                                                                <ItemTemplate>
                                                                    <tr>
                                                                        <td>
                                                                            <input type="checkbox" id='chk_buyerRange_<%#Eval("companyid") %>' value='<%#Eval("companyid") %>'
                                                                                <%#Convert.ToBoolean(Eval("isChecked"))?"checked":"" %> name="type" /><%#Eval("company")%>
                                                                        </td>
                                                                    </tr>
                                                                </ItemTemplate>
                                                            </asp:Repeater>
                                                        </table>
                                                    </div>
                                                </li>
                                                <li>
                                                    <label>
                                                        &nbsp;
                                                    </label>
                                                    <span style="<%=power>=2?"": "display:none" %>">
                                                        <asp:Button runat="server" ID="btn_Save" Text="保 存" OnClick="btn_Save_Click"/>
                                                    </span>
                                                    <input type="button" id="btn_Return" value="返 回" onclick="winClose();" />
                                                </li>
                                            </ul>
                                        </div>
                                    </Body>
                                </ext:Panel>
                            </ext:LayoutColumn>
                        </ext:ColumnLayout>
                    </Body>
                </ext:Panel>
            </Body>
        </ext:Panel>
    </div>
    <input id="hd_ddl" runat="server" type="hidden" />
    <input id="hd_str" runat="server" type="hidden" value="" />
    <input id="hd_autoAdd" runat="server" type="hidden" />
    <input id="hd_buyers" runat="server" type="hidden" />

    <script type="text/javascript">


        var hdstr = document.getElementById('hd_str').value;
        if (hdstr != "" && hdstr != 0)
            bindPhotoList2(document.getElementById('hd_str').value); 
       
    </script>

    </form>
</body>
</html>
